<template>
	<view scroll-with-animation scroll-y style="height:100vh;position: relative;background-color: #F8FBFB;padding-top: 20rpx;padding-bottom: 50rpx;overflow-y: auto;padding-bottom: 120rpx;">
		<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;">
			<view style="border-bottom: 2rpx solid #E1E1E1;padding-top: 20rpx;padding-bottom: 20rpx;font-size: 30rpx;font-weight: bolder;">
				患者信息
			</view>
			<view style="display: flex;align-items: center;" class="crad-row">
				<view style="padding-right: 20rpx;border-right: 2rpx solid #E1E1E1;font-weight: bolder;">{{info.usrPersonalFileName}}</view>
				<view style="padding-left: 20rpx;">{{info.age}}</view>
			</view>
			<view class="crad-row" style="display: flex;align-items: center;justify-content: space-between;">
				<view>联系电话：</view>
				<view style="margin-right: 40rpx;">{{info.usrPersonalFileMobile}}</view>
			</view>
			<view class="crad-row" style="display: flex;align-items: center;justify-content: space-between;">
				<view>身份证号：</view>
				<view style="margin-right: 40rpx;">{{info.identity}}</view>
			</view>
			<view class="crad-row" style="display: flex;align-items: center;justify-content: space-between;">
				<view>诊断结果：</view>
				<view style="margin-right: 40rpx;">{{info.diseaseName}}</view>
			</view>
			<view class="crad-row" style="display: flex;align-items: center;justify-content: space-between;">
				<view>就诊时间：</view>
				<view style="margin-right: 40rpx;">{{formatDate(info.visitTime)}}</view>
			</view>
		</view>
		
		<view v-if="info.flowStatus==0" class="card-plane" style="margin-bottom: 20rpx;">
			<view style="border-bottom: 2rpx solid #E1E1E1;padding-top: 20rpx;padding-bottom: 20rpx;font-size: 30rpx;font-weight: bolder;">
				患者自述
			</view>
			<view class="crad-row row-border">
				<view>1、您在我院住院治疗的结果是？</view>
				<radio-group @change="changeZLXG">
					<view class="card-answer">
						<label class="radio"><radio value="治愈" style="transform:scale(0.6)"/>治愈</label>
						<label class="radio"><radio value="好转" style="transform:scale(0.6)"/>好转</label>
						<label class="radio"><radio value="恶化" style="transform:scale(0.6)"/>恶化</label>
						<label class="radio"><radio value="无变化" style="transform:scale(0.6)"/>无变化</label>
					</view>
				</radio-group>
			</view>
			<view class="crad-row row-border">
				<view>2、目前的身体情况？</view>
				<radio-group @change="changeSTQK">
					<view class="card-answer">
						<label class="radio"><radio value="无症状" style="transform:scale(0.6)"/>无症状</label>
						<label class="radio"><radio value="新症状出现" style="transform:scale(0.6)"/>新症状出现</label>
						<label class="radio"><radio value="原症状持续" style="transform:scale(0.6)"/>原症状持续</label>
						<label class="radio"><radio value="需就诊" style="transform:scale(0.6)"/>需就诊</label>
					</view>
				</radio-group>
			</view>
			<view class="crad-row row-border">
				<view>3、健康检测</view>
				<view class="card-answer" style="display: flex;flex-direction: column;align-items: flex-start;">
					<view style="margin-top: 10rpx;display: flex;align-items: center;">
						<text>血压：</text><input class="uni-input" v-model="followData.bloodPressure" style="width: 100rpx;border-bottom: 2rpx solid #000000;"/><text>mmHg</text>
					</view>
					<view style="margin-top: 10rpx;display: flex;align-items: center;">
						<text>血糖：</text><input class="uni-input" v-model="followData.bloodSugar" style="width: 100rpx;border-bottom: 2rpx solid #000000;"/><text>mmol/L</text>
					</view>
					<view style="margin-top: 10rpx;display: flex;align-items: center;">
						<text>体温：</text><input class="uni-input" v-model="followData.flowTemperature" style="width: 100rpx;border-bottom: 2rpx solid #000000;"/><text>℃</text>
					</view>
				</view>
			</view>
			<view class="crad-row row-border">
				<view>4、有无并发症？</view>
				<radio-group @change="changeBFZ">
					<view class="card-answer" style="justify-content: space-between;">
						<label class="radio"><radio value="1" style="transform:scale(0.6)"/>有</label>
						<label class="radio"><radio value="0" style="transform:scale(0.6)"/>无</label>
					</view>
				</radio-group>
			</view>
			<view class="crad-row row-border">
				<view>5、您的服药依从性如何？</view>
				<radio-group @change="changeYCX">
					<view class="card-answer" style="justify-content: space-around;">
						<label class="radio"><radio value="规律" style="transform:scale(0.6)"/>规律</label>
						<label class="radio"><radio value="间断" style="transform:scale(0.6)"/>间断</label>
						<label class="radio"><radio value="不服药" style="transform:scale(0.6)"/>不服药</label>
					</view>
				</radio-group>
			</view>
			<view class="crad-row row-border">
				<view>6、有无出现药品不良反应？</view>
				<radio-group @change="changeBLFY">
					<view class="card-answer" style="justify-content: space-between;">
						<label class="radio"><radio value="1" style="transform:scale(0.6)"/>有</label>
						<label class="radio"><radio value="0" style="transform:scale(0.6)"/>无</label>
					</view>
				</radio-group>
				<view style="margin-top: 20rpx;margin-bottom: 20rpx;">您出现的药物不良反应是：</view>
				<view style="width:calc(100% - 180rpx );margin-bottom: 20rpx;">
					<textarea placeholder="药物不良反应" v-model="followData.reactionDescribe" style="background: #EDF6F5;height: 100rpx;padding:10rpx;"/>
				</view>
			</view>
			<view class="crad-row row-border">
				<view>7、您的遵医行为如何？</view>
				<radio-group @change="changeZYXW">
					<view class="card-answer" style="justify-content: space-around;">
						<label class="radio"><radio value="良好" style="transform:scale(0.6)"/>良好</label>
						<label class="radio"><radio value="一般" style="transform:scale(0.6)"/>一般</label>
						<label class="radio"><radio value="差" style="transform:scale(0.6)"/>差</label>
					</view>
				</radio-group>
			</view>
			<view class="crad-row">
				<view>8、您最近的情绪如何？</view>
				<radio-group @change="changeQX">
					<view class="card-answer" style="justify-content: space-around;">
						<label class="radio"><radio value="良好" style="transform:scale(0.6)"/>良好</label>
						<label class="radio"><radio value="一般" style="transform:scale(0.6)"/>一般</label>
						<label class="radio"><radio value="差" style="transform:scale(0.6)"/>差</label>
					</view>
				</radio-group>
			</view>
		</view>
		
		<view v-if="info.flowStatus==1||info.flowStatus==2" class="card-plane" style="margin-bottom: 20rpx;">
			<view style="border-bottom: 2rpx solid #E1E1E1;padding-top: 20rpx;padding-bottom: 20rpx;font-size: 30rpx;font-weight: bolder;">
				患者自述
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>1、您在我院住院治疗的结果是？</view>
				<radio-group>
					<view class="card-answer" style="color: #9e9e9e;">
						{{info.flowResult}}
					</view>
				</radio-group>
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>2、目前的身体情况？</view>
				<radio-group>
					<view class="card-answer" style="color: #9e9e9e;">
						{{info.flowBody}}
					</view>
				</radio-group>
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>3、健康检测</view>
				<view class="card-answer" style="color: #9e9e9e;">
					<view style="margin-top: 10rpx;" v-if="info.bloodPressure==undefined">
						血压：____无____ 
					</view>
					<view style="margin-top: 10rpx;" v-if="info.bloodPressure!=undefined">
						血压：_____{{info.bloodPressure}}____ mmHg
					</view>
					<view style="margin-top: 10rpx;" v-if="info.bloodSugar==undefined">
						血糖：____无_____
					</view>
					<view style="margin-top: 10rpx;" v-if="info.bloodSugar!=undefined">
						血糖：____{{info.bloodSugar}}_____ mmol/L
					</view>
					<view style="margin-top: 10rpx;" v-if="info.flowTemperature==undefined">
						体温：____无_____ ℃
					</view>
					<view style="margin-top: 10rpx;" v-if="info.flowTemperature!=undefined">
						体温：____{{info.flowTemperature}}_____ ℃
					</view>
				</view>
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>4、有无并发症？</view>
				<view class="card-answer"  style="color: #9e9e9e;" v-if="info.isConcurrent==0">
					无
				</view>
				<view class="card-answer"  style="color: #9e9e9e;" v-if="info.isConcurrent==1">
					有
				</view>
				
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>5、您的服药依从性如何？</view>
				<view class="card-answer" style="color: #9e9e9e;">
						{{info.serviceCompliance}}
				</view>
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>6、有无出现药品不良反应？</view>
				<view class="card-answer" style="color: #9e9e9e;" v-if="info.drugReaction==0">
						无
				</view>
				<view class="card-answer" style="color: #9e9e9e;" v-if="info.drugReaction==1">
						有
				</view>
				<view style="margin-top: 20rpx;margin-bottom: 20rpx;">您出现的药物不良反应是：</view>
				<view style="width:calc(100% - 180rpx );margin-bottom: 20rpx;color: #9e9e9e;">
					{{info.reactionDescribe}}
				</view>
			</view>
			<view class="crad-row row-border" style="padding-bottom: 10rpx;">
				<view>7、您的遵医行为如何？</view>
				<view class="card-answer" style="color: #9e9e9e;">
					{{info.medicalBehavior}}
				</view>
			</view>
			<view class="crad-row" style="padding-bottom: 10rpx;">
				<view>8、您最近的情绪如何？</view>
				<view class="card-answer" style="color: #9e9e9e;">
					{{info.recentMood}}
				</view>
			</view>
		</view>
		
	
		
		<view v-if="info.flowStatus==1||info.flowStatus==2" class="card-plane">
			<view style="border-bottom: 2rpx solid #E1E1E1;padding-top: 20rpx;padding-bottom: 20rpx;font-size: 30rpx;font-weight: bolder;">
				医生批复
			</view>
			<view class="crad-row">
				<view style="margin-top: 20rpx;margin-bottom: 20rpx;">此次随访的指导意见</view>
				<view style="width:calc(100% - 180rpx );margin-bottom: 20rpx;" v-if="info.flowGuidance!=undefined">
					{{info.flowGuidance}}
				</view>
				<view style="width:calc(100% - 180rpx );margin-bottom: 20rpx;" v-if="info.flowGuidance==undefined">
					无
				</view>
			</view>
			<view class="crad-row">
				<view>此次随访分类：</view>
				<radio-group>
					<view class="card-answer" v-if="info.flowSort!=undefined">
						{{info.flowSort}}
					</view>
					<view class="card-answer" v-if="info.flowSort==undefined">
						无
					</view>
					<!-- <view class="card-answer" style="justify-content: space-around;">
						<label class="radio"><radio value="1" style="transform:scale(0.6)"/>控制满意</label>
						<label class="radio"><radio value="2" style="transform:scale(0.6)"/>控制不满意</label>
						<label class="radio"><radio value="3" style="transform:scale(0.6)"/>不良反应</label>
						<label class="radio"><radio value="4" style="transform:scale(0.6)"/>并发症</label>
					</view> -->
				</radio-group>
			</view>
		</view>
		<view v-if="info.flowStatus==0" style="width: 100%;margin-bottom: 40rpx;margin-top: 20rpx;">
			<view class="add-btn" @click="submitUsrFollowUp()">提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wx: "https://app.mzmzb.com",//http://localhost:6110 https://app.mzmzb.com
				followId:undefined,//随访表ID
				problemsList:[],
				info:'',//随访详情
				followData: { // 随访保存数据
					flowResult: undefined, // 治疗效果
					flowBody: undefined, // 身体情况
					bloodPressure: undefined, // 血压
					bloodSugar:undefined, // 血糖
					flowTemperature:undefined,// 温度
					isConcurrent:undefined,// 并发症
					serviceCompliance:undefined,
					drugReaction:undefined,
					reactionDescribe: '',
					medicalBehavior:undefined,
					recentMood:undefined,
					submitType:1,
					id:undefined
				}
			};
		},
		onLoad(option) {
			this.followId = option.followId
			let orderId = option.orderId
			let readed = option.readed
			if(orderId){
				this.settingRead(orderId,readed);
			}
			this.queryDetails();
		},
		methods: {
			//设置已读状态
			settingRead(orderId,readed){
				var that = this;
				if(readed == 0){
					var that = this;
					uni.request({
						url: 'https://app.mzmzb.com/application-usrapp/wx/settingRead.tz',
						data: {orderId : orderId},
						method:"GET",
						success: (res) => {
							if(res.data.success){
								let prevPage = pages[pages.length-2]
								prevPage.$vm.noReadNum--;
								// if(that.noReadNum>0){
								// 	that.noReadNum--
								// }
							}
						}
					});
				}
			},
			changeZLXG(evt){
				this.followData.flowResult = evt.target.value
			},
			changeSTQK(evt){
				this.followData.flowBody = evt.target.value
			},
			changeBFZ(evt){
				this.followData.isConcurrent = evt.target.value
			},
			changeYCX(evt){
				this.followData.serviceCompliance = evt.target.value
			},
			changeBLFY(evt){
				this.followData.drugReaction = evt.target.value
			},
			changeZYXW(evt){
				this.followData.medicalBehavior = evt.target.value
			},
			changeQX(evt){
				this.followData.recentMood = evt.target.value
			},
			formatDate(value) {
			  var date = new Date(value);
			  var y = date.getFullYear(),
			    m = date.getMonth() + 1,
			    d = date.getDate(),
			    h = date.getHours(),
			    i = date.getMinutes(),
			    s = date.getSeconds();
			  if (m < 10) { m = '0' + m; }
			  if (d < 10) { d = '0' + d; }
			  if (h < 10) { h = '0' + h; }
			  if (i < 10) { i = '0' + i; }
			  if (s < 10) { s = '0' + s; }
			  var t = y + '-' + m + '-' + d 
			  return t;
			},
			//查询随访详情
			queryDetails() {
				var that = this
				uni.request({
					url: this.wx + '/application-usrapp/followUp/queryDetails.tz',
					data: {
						followId: that.followId,
					},
					header: {
						'content-type': 'application/json'
					},
					success:(res) =>{
						if (res.data.success) {
							console.log(res)
							that.info = res.data.result;
						} else {
							uni.showToast({
								title: '查询失败'
							})
						}
					}
				})
			},
			//提交
			submitUsrFollowUp(){
				var that=this;
				that.followData.id=that.followId
				if(!this.followData.flowResult){
					uni.showToast({
						title: '治疗效果不能为空！',
						icon:'error'
					})
					return;
				}
				if(!this.followData.flowBody){
					uni.showToast({
						title: '身体情况不能为空！',
						icon:'error'
					})
					return;
				}
				if(!this.followData.bloodPressure){
					uni.showToast({
						title: '血压不能为空！',
						icon:'error'
					})
					return;
				}
				if(!this.followData.bloodSugar){
					uni.showToast({
						title: '血糖不能为空！',
						icon:'error'
					})
					return;
				}
				if(!this.followData.flowTemperature){
					uni.showToast({
						title: '温度不能为空！',
						icon:'error'
					})
					return;
				}
				if(!this.followData.isConcurrent){
					uni.showToast({
						title: '并发症不能为空！',
						icon:'error'
					})
					return;
				}
				
				if(!this.followData.serviceCompliance){
					uni.showToast({
						title: '服药依从性不能为空！',
						icon:'error'
					})
					return;
				}
				
				if(!this.followData.drugReaction){
					uni.showToast({
						title: '请选择是否有不良反应！',
						icon:'error'
					})
					return;
				}else{
					if(this.followData.drugReaction == '1'){
						if(!this.followData.reactionDescribe){
							uni.showToast({
								title: '药物不良反应不能为空！',
								icon:'error'
							})
						}
					}
				}
				if(!this.followData.medicalBehavior){
					uni.showToast({
						title: '遵医行为不能为空！',
						icon:'error'
					})
					return;
				}
				if(!this.followData.recentMood){
					uni.showToast({
						title: '请选择情绪如何！',
						icon:'error'
					})
					return;
				}
				
				uni.request({
					url: that.wx + '/application-usrapp/followUp/submitUsrFollowUp.tz',
					data: that.followData,
					header : {'content-type':'application/x-www-form-urlencoded'},
					method:"POST",
					success: (item) => {
						console.log(item)
						if(item.data.success){
							uni.navigateTo({
								url: '/pages3/chufangcg/index?msg=保存成功'
							})
						}else{
							uni.showToast({
								title: '操作失败！',
								duration: 3000,
								icon:'error'
							})
						}
					}
				})
			}
		}
	};
</script>

<style lang="less">
	.add-btn{
		margin: auto;
		height: 88rpx;
		line-height: 88rpx;
		width: 90%;
		background: linear-gradient(90deg, #23E0D3 0%, #00BAAD 100%);
		box-shadow: 0px 20rpx 25rpx 0px rgba(0, 186, 173, 0.4);
		border-radius: 44rpx;
		color: #FFFFFF;
		text-align: center;
	}
	.card-plane{
		background-color: #FFFFFF;
		padding-left: 40rpx;
		padding-bottom: 20rpx;
		margin-top: 20rpx;
	}
	.crad-row{
		margin-top: 20rpx;
		.card-answer{
			display: flex;
			align-items: center;
			justify-content: flex-start;
			flex-flow: wrap;
			margin-top: 20rpx;
			width: calc( 100% - 40rpx );
			.radio{
				margin-right: 20rpx;
			}
		}
	}
	.row-border{
		border-bottom: 2rpx solid #E1E1E1;
	}
</style>
